Imports System.Data
Partial Class Admin_frmModifyCity
    Inherits System.Web.UI.Page
    Dim VarCityId As String
    Dim _CityVO As New CityVo
    Dim _BO As New Bo
    Dim _StateVO As New StateVo
    Dim _CountryVO As New CountryVo
    Dim _EmployeeId As String
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Try
            SetData()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Session("EmpId") = _EmployeeId
    End Sub
    Public Sub ClearAll()
        lblCityId.Text = ""
        txtCityName.Text = ""
        MsgBox("City Updated")
    End Sub
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        _EmployeeId = Session("EmpId")
        If _EmployeeId = "" Then
            Response.Redirect("../Client/frmLogin.aspx")
        End If
        VarCityId = Request.QueryString("CityId")
        If Not IsPostBack Then
            GetCityData()
            CountryData()
            StateData()
        End If
    End Sub
    Public Sub CountryData()
        Dim dtCountry As DataTable
        dtCountry = _BO.getcountry()
        ddlCountry.DataSource = dtCountry
        ddlCountry.DataValueField = dtCountry.Columns(0).ToString
        ddlCountry.DataTextField = dtCountry.Columns(1).ToString
        ddlCountry.DataBind()
    End Sub
    Sub StateData()
        Dim dtState As DataTable
        dtState = _BO.getstate(ddlCountry.Text)
        ddlState.DataSource = dtState
        ddlState.DataValueField = dtState.Columns(1).ToString
        ddlState.DataTextField = dtState.Columns(2).ToString
        ddlState.DataBind()
    End Sub
    Protected Sub ddlCountry_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCountry.SelectedIndexChanged
        StateData()
    End Sub
    Sub SetData()
        _CityVO.CountryId = ddlCountry.SelectedValue
        _CityVO.StateId = ddlState.SelectedValue
        _CityVO.CityId = lblCityId.Text
        _CityVO.CityName = txtCityName.Text
        _BO.ModifyCity(_CityVO)
        MsgBox("City Updated")
        Response.Redirect("frmTabCity.aspx", False)
    End Sub
    Sub GetCityData()
        _CityVO = _BO.getCityById(VarCityId)
        _CountryVO = _BO.getCountryById(_CityVO.CountryId)
        ddlCountry.Text = _CountryVO.CountryName
        _StateVO = _BO.getStateById(_CityVO.StateId)
        ddlState.Text = _StateVO.StateName
        ddlCountry.SelectedValue = _CityVO.CountryId
        _StateVO = _BO.getStateById(_CityVO.StateId)
        ddlState.Text = _StateVO.StateName
        ddlState.SelectedValue = ""
        ddlState.SelectedValue = _CityVO.StateId
        lblCityId.Text = _CityVO.CityId
        txtCityName.Text = _CityVO.CityName
    End Sub

    Protected Sub btnReset_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReset.Click
        lblCityId.Text = ""
        txtCityName.Text = ""
    End Sub
End Class
